/*=============================================================================
D3DPostProcess : Direct3D specific post processing special effects
Copyright (c) 2001 Crytek Studios. All Rights Reserved.

=============================================================================*/

#ifndef _D3DPOSTPROCESS_H_
#define _D3DPOSTPROCESS_H_

#include "../Common/PostProcess/PostEffects.h"

struct SD3DPostEffectsUtils: public SPostEffectsUtils
{
//  friend class CD3D9Renderer;

public:

	enum EFilterType
	{
		FilterType_Box,
		FilterType_Tent,
		FilterType_Gauss,
		FilterType_Lanczos,
	};

	void CopyTextureToScreen(CTexture *&pSrc, const RECT * srcRegion = NULL);
	void CopyScreenToTexture(CTexture *&pDst, const RECT * srcRegion = NULL);
	void StretchRect(CTexture *pSrc, CTexture *&pDst, bool bCoarseDepthInAlpha = false, bool bDecodeSrcRGBK= false, bool bEncodeDstRGBK = false, bool bBigDownsample = false, bool bMaxDownsample=false, bool bBindMultisampled = false);
	// Downsample source to target using specified filter
	// If bSetTarget is not set then destination target is ignored and currently set render target is used instead
	void Downsample(CTexture * pSrc, CTexture * pDst, int nSrcW, int nSrcH, int nDstW, int nDstH, EFilterType eFilter = FilterType_Box, bool bSetTarget = true);
  void DownscaleSubregion(CTexture *pSrc, CTexture *&pDst, const RECT * srcRect, const RECT * dstRect, bool bMaxDownsample, bool bChannelSwap = false);
	void TexBlurIterative(CTexture *pTex, int nIterationsMul = 1, bool bDilate = false, CTexture *pBlurTmp = 0); // 2 terations minimum (src => temp => src)
	void TexBlurGaussian(CTexture *pTex, int nAmount, float fScale, float fDistribution, bool bAlphaOnly, CTexture *pMask = 0, bool bSRGB = false, CTexture *pBlurTmp = 0);
	void BilateralBlurring(CTexture *pSrc, CTexture *pDest);
	void TexBlurDirectional(CTexture *pTex, const Vec2 &vDir, int nIterationsMul = 1, CTexture *pBlurTmp = 0); // 2 terations minimum (src => temp => src)
		
	// Begins drawing a stencil pre-pass mask
	void BeginStencilPrePass( const bool bAddToStencil = false, const bool bDebug=false, const bool bResetStencil=false , const uint8 nStencilRefReset = 0);
	// Ends drawing a stencil pre-pass mask
	void EndStencilPrePass( );
	// Setup render states for passes using stencil masks
	void SetupStencilStates( int32 nStFunc );

	// Override fill mode (wireframe/point) with solid mode
	void SetFillModeSolid(bool bEnable);

	void BackBufferTexturePush(bool bPushPrev = false, bool bForceResolve = false);
	void BackBufferTexturePop();
	void ResetBackBufferTexStates()
	{
		m_nCurrBackBufferID = 0;
		m_pCurrBackBuffer[0] = m_pCurrBackBuffer[1] = 0;
	}

	CTexture *GetBackBufferTexture();











  SD3DSurface *GetDepthSurface( CTexture *pTex );
  void ResolveRT( CTexture *&pDst, const RECT * pSrcRect );

  ////////////////////////////////////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////

  static SD3DPostEffectsUtils &GetInstance()
  {
    return m_pInstance;
  }


private:

  static SD3DPostEffectsUtils m_pInstance;

	SD3DPostEffectsUtils(): m_nCurrBackBufferID(0)
	{ 
		m_pCurrBackBuffer[0] = m_pCurrBackBuffer[1] = 0;
	}

  virtual ~SD3DPostEffectsUtils() 
  { 
  }

private:

	CTexture *m_pCurrBackBuffer[2]; // backbuffer textures used for ping-pong bettwen rt's (avoid stretchrects/copy/image)
	uint32 m_nCurrBackBufferID;
	

};

// to be removed
#define GetUtils() SD3DPostEffectsUtils::GetInstance()

#define PostProcessUtils() SD3DPostEffectsUtils::GetInstance()

#endif
